<?php
namespace app\admin\controller;
use think\Controller;
use think\Cookie;
use think\Request;
use think\Session;

class Login extends Controller{

    function __construct(Request $request = null)
    {
        parent::__construct($request);
        header("Content-type:text/html;charset=utf-8");
    }

    function login(){

        if(Session::get('adminUid')){
            $this->redirect('admin/index/index');
        }

        return view('login');
    }


    function doLogin(){

        $data = Request::instance()->post();

        $user = model('admin')->checkUser(trim($data['loginUsername']),trim($data['loginPassword']));

        if($user){
            Session::set('adminUid',$user->id);
            Cookie::set('adminUid',$user->id,7*24*3600);
            if($from = Session::get('urlFrom')){
                $this->redirect($from);
            }
            else{
                $this->redirect('admin/index/index');
            }

        }else{
            die('账号或密码错误');
        }


    }



    function loginOut(){

        Session::delete('adminUid');
        Cookie::delete('adminUid');

        $this->redirect('admin/login/login');

    }






















}